﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApplication.MyFtp
{
    public class SocketHelper : IDisposable
    {
        static public TcpListener CreateTcpListener(int nPort)
        {
            TcpListener listener = null;

            try
            {
                listener = new TcpListener(IPAddress.Any, nPort);
            }
            catch (SocketException)
            {
                listener = null;
            }

            return listener;
        }

        static public TcpClient CreateTcpClient(string sAddress, int nPort)
        {
            TcpClient client = null;

            try
            {
                client = new TcpClient(sAddress, nPort);
            }
            catch (SocketException)
            {
                client = null;
            }

            return client;
        }

        ~SocketHelper()
        {
          Dispose(false);
        }
        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Dispose Member and Field
        /// </summary>
        /// <param name="disposing"></param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
            }
        }
    }
}
